package com.zqxq.lottery.service.user.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.common.utils.DateUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.config.YmlConfig;
import com.zqxq.lottery.entity.bo.SmsBO;
import com.zqxq.lottery.entity.bo.sys.SysActivityBO;
import com.zqxq.lottery.entity.bo.user.UserInfoCMSBO;
import com.zqxq.lottery.entity.enums.ActivityIdEnum;
import com.zqxq.lottery.entity.o2o.user.UserInfoO2O;
import com.zqxq.lottery.entity.po.export.ExpertInfoPO;
import com.zqxq.lottery.entity.po.sys.SysConfigPO;
import com.zqxq.lottery.entity.po.user.*;
import com.zqxq.lottery.entity.vo.user.UserInfoCMSVO;
import com.zqxq.lottery.entity.vo.user.UserInfoVO;
import com.zqxq.lottery.feign.ApiLotteryServerFeignClient;
import com.zqxq.lottery.mapper.order.UserOrderMapper;
import com.zqxq.lottery.mapper.sys.SysActivityMapper;
import com.zqxq.lottery.mapper.sys.SysConfigMapper;
import com.zqxq.lottery.mapper.user.*;
import com.zqxq.lottery.mq.Sender;
import com.zqxq.lottery.service.expert.IExpertInfoService;
import com.zqxq.lottery.service.sys.ISysActivityService;
import com.zqxq.lottery.service.user.IUserCashService;
import com.zqxq.lottery.service.user.IUserCouponService;
import com.zqxq.lottery.service.user.IUserInfoService;
import com.zqxq.lottery.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;


@Service
@Slf4j
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper,UserInfoPO> implements IUserInfoService {

    @Autowired
    private UserFundsMapper userFundsMapper;
    @Autowired
    private UserAlipayMapper userAlipayMapper;
    @Autowired
    private IUserCashService userCashService;
    @Autowired
    private YmlConfig ymlConfig;
    @Autowired
    private SysActivityMapper sysActivityMapper;
    @Autowired
    private UserInviteMapper userInviteMapper;
    @Autowired
    private ISysActivityService sysActivityService;
    @Autowired
    private UserActivityMapper userActivityMapper;
    @Autowired
    private UserAgentMapper userAgentMapper;
    @Autowired
    private Sender sender;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private IUserCouponService userCouponService;
    @Autowired
    private IExpertInfoService expertInfoService;
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private UserSignMapper userSignMapper;
    @Autowired
    private UserOrderMapper userOrderMapper;
    @Autowired
    private ApiLotteryServerFeignClient apiLotteryServerFeignClient;
    @Autowired
    private UserCashMapper userCashMapper;
    @Autowired
    private UserCouponMapper userCouponMapper;
    @Override
    public Page<UserInfoCMSVO> queryPageList(UserInfoCMSBO bo) {
        Page<UserInfoCMSVO> page = new Page(bo.getPageNo(), bo.getPageSize());
        List<UserInfoCMSVO> userInfoCMSVOList = this.baseMapper.queryPageList(page, bo);
        page.setRecords(userInfoCMSVOList);
        return page;
    }
    @Override
    public List<UserInfoCMSVO> query(UserInfoCMSBO bo){
        return this.baseMapper.queryPageList(bo);
    }
    @Override
    public UserInfoCMSVO getCmsVO(Long userId) {
        return this.baseMapper.getCmsVO(userId);
    }

    @Override
    public UserInfoVO getVO(Long userId) {
        //该接口只能 app用，且不能做计算
        UserInfoVO vo = this.baseMapper.getVO(userId);
        if (null == vo)
            vo = new UserInfoVO();
        ExpertInfoPO expertInfoPO = expertInfoService.getExpertInfo(userId);
        if(expertInfoPO!=null){
            vo.setIsExpert("1");
        }else{
            vo.setIsExpert("0");
        }
        BigDecimal cashAble = new BigDecimal(vo.getCashAble()).setScale(2,BigDecimal.ROUND_DOWN);
        vo.setCashAble(DispatcherUtils.parseString(cashAble));
        BigDecimal balance = new BigDecimal(vo.getBalance()).setScale(2,BigDecimal.ROUND_DOWN);
        vo.setBalance(DispatcherUtils.parseString(balance));
        SysConfigPO sysConfigPO = sysConfigMapper.getByKey("OFFICIAL_QQ_GROUP");
        if(sysConfigPO!=null){
            vo.setOfficialQQGroup(sysConfigPO.getCval());
        }
        SysConfigPO sysConfigPOQQ = sysConfigMapper.getByKey("OFFICIAL_QQ");
        if(sysConfigPOQQ!=null){
            vo.setOfficialQQ(sysConfigPOQQ.getCval());
        }
        SysConfigPO sysConfigPOWechat = sysConfigMapper.getByKey("OFFICIAL_WECHAT");
        if(sysConfigPOWechat!=null){
            vo.setOfficialWechat(sysConfigPOWechat.getCval());
        }
        SysConfigPO sysConfigPOExchangeRatio = sysConfigMapper.getByKey("EXCHANGE_DIAMOND_RATIO");
        if(sysConfigPOExchangeRatio!=null){
            vo.setExchangeDiamondRatio(sysConfigPOExchangeRatio.getCval());
        }
        SysConfigPO sysConfigPORechargeSign = sysConfigMapper.getByKey("RECHARGE_SIGN");
        if(sysConfigPORechargeSign!=null){
            vo.setRechargeSign(sysConfigPORechargeSign.getCval());
        }
        Wrapper couponWrapper = new EntityWrapper();
        couponWrapper.eq("user_id",userId);
        couponWrapper.eq("status","0");
        vo.setCouponNum(String.valueOf(userCouponMapper.selectCount(couponWrapper)));
        userCouponMapper.selectCount(couponWrapper);
        int count = userSignMapper.selectToDayCount(userId);
        vo.setToDaySignStatus(String.valueOf(count));
        return vo;
    }
    @Override
    public UserInfoVO getUserByMobile(String mobile) {
        //该接口只能 app用，且不能做计算
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setMobile(mobile);
        userInfoPO = baseMapper.selectOne(userInfoPO);
        return UserInfoO2O.toVO(userInfoPO);
    }
    @Override
    public Integer getUserInfoByMobile(String mobile) {
        //该接口只能 app用，且不能做计算
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("mobile",mobile);
        Integer count = this.baseMapper.selectCount(wrapper);
        /*if(count>0){
            //已经注册的用户，判断是否参加188大礼包活动，如果没有则发送188大礼包
            List<UserInfoPO> userInfoPOList = this.baseMapper.selectList(wrapper);
            if(userInfoPOList!=null && userInfoPOList.size()!=0){
                UserInfoPO userInfoPO = userInfoPOList.get(0);
                Integer activityCount = userActivityMapper.getCountByUIdAId(userInfoPO.getId(),1L);
                if(activityCount==0){
                    //该用户没有参加过此活动，发放188大礼包
                    try {
                        //参加新用户领券活动
                        SysActivityBO sysActivityBO = new SysActivityBO();
                        sysActivityBO.setActivityId(ActivityIdEnum.REGISTER.getId());
                        sysActivityBO.setUserId(userInfoPO.getId());
                        sysActivityService.saveUserActivity(sysActivityBO);
                    }catch (Exception e){
                        log.error("sysActivityService.saveUserActivity error",e);
                    }
                }
            }
        }*/
        return count;
    }


    @Transactional
    @Override
    //新用户，添加资金表、支付宝
    public boolean saveUserInfo(UserInfoVO vo) {
        UserInfoPO po = UserInfoO2O.toPO(vo);
        boolean userFlag = false;
        boolean isFirstLogin = false;
        if (!StringUtils.isEmpty(vo.getInviterId()) && StringUtils.isEmpty(vo.getChannel())) {
            po.setChannel("invite");
        }
        //更新用户最后登录时间
        if (StrUtils.isNotEmpty(po.getEquipment_id())){
            po.setLogin_time(new Date());
            //判断用户是否为首次登陆
            UserInfoPO userInfoPO = new UserInfoPO();
            userInfoPO.setMobile(po.getMobile());
            userInfoPO = this.baseMapper.selectOne(userInfoPO);
            if (userInfoPO == null || StrUtils.isEmpty(userInfoPO.getEquipment_id())){
                isFirstLogin = true;
            }
        }
        if (!StringUtils.isEmpty(vo.getAppKey())) {
            po.setApp_key(vo.getAppKey());
        }
        //新用户
        if(this.baseMapper.updateUserInfoById(po) < 1){
            userFlag = true;
            po.setIs_send_coupon(0);
            this.baseMapper.insert(po);
//            sendLotBean(String.valueOf(po.getMobile()));
            //发送短信，“注册成功。加官方qq群xxxxx，更多活动早知道。”
            SmsBO bo = new SmsBO();
            bo.setMobile(vo.getMobile());
            bo.setCodeType(0);
//            SysConfigPO sysConfigPO = sysConfigMapper.getByKey("OFFICIAL_QQ_GROUP");
//            bo.setMsg("注册成功。加官方qq群"+sysConfigPO.getCval()+"，更多活动早知道。");
//            apiLotteryServerFeignClient.sendMsg(bo);
            if (StrUtils.isNotEmpty(po.getEquipment_id())){
                //首次注册并登陆
            }
        }else{
//            saveUserCoupon(String.valueOf(po.getMobile()));
        }

        //资金表
        UserFundsPO fundsPO = new UserFundsPO();
        fundsPO.setUser_id(po.getId());
        fundsPO.setUpdate_time(DateUtils.getCurrentDate());
        if(userFundsMapper.updateById(fundsPO) < 1){
            userFundsMapper.insert(fundsPO);
        }
        //支付宝
        UserAlipayPO alipayPO = null;
        if(StrUtils.isNotEmpty(vo.getAlipayAccount())){
            alipayPO = new UserAlipayPO();
            alipayPO.setId(po.getId());
            alipayPO.setUser_id(po.getId());
            alipayPO.setAlipay_account(vo.getAlipayAccount());
        }
        if(alipayPO != null) {
            if(userAlipayMapper.updateById(alipayPO) < 1){
                userAlipayMapper.insert(alipayPO);
            }
            fundsPO.setAlipay_bind(1);
        }
        if (userFlag && !StrUtils.isEmpty(vo.getInviterId())){
            //注册用户通过活动推广而来
            try {
                //保存用户邀请记录
                UserInfoPO inviterPO = baseMapper.selectById(vo.getInviterId());
                UserInviteRecordPO inviteRecordPO = new UserInviteRecordPO();
                //查询用户是否已经被邀请
                inviteRecordPO.setUser_id(po.getId());
                UserInviteRecordPO recordPO = userInviteMapper.selectOne(inviteRecordPO);
                if (recordPO == null){
                    inviteRecordPO.setId(ymlConfig.getPkId());
                    inviteRecordPO.setUser_id(po.getId());
                    inviteRecordPO.setUser_phone(vo.getMobile());
                    inviteRecordPO.setInviter_phone(inviterPO.getMobile());
                    inviteRecordPO.setInviter_id(inviterPO.getId());
                    userInviteMapper.insert(inviteRecordPO);
                }

            }catch (Exception e){
                log.info("用户参与活动失败");
            }
        }
        //生成用户首次登录活动奖励
//        if (isFirstLogin){
//            newUserLoginCoupon(po.getMobile());
//        }

        return true;
    }

    public void newUserLoginCoupon(String mobile){
        try {
            UserInfoPO userInfoPO = new UserInfoPO();
            userInfoPO.setMobile(mobile);
            userInfoPO = this.baseMapper.selectOne(userInfoPO);
            if (userInfoPO != null) {
                //已经注册的用户，判断是否参加188大礼包活动，如果没有则发送188大礼包
                Integer activityCount = userActivityMapper.getCountByUIdAId(userInfoPO.getId(), ActivityIdEnum.LOGIN.getId());
                if (activityCount == 0) {
                    //该用户没有参加过此活动
                    //参加新用户领券活动
                    SysActivityBO sysActivityBO = new SysActivityBO();
                    sysActivityBO.setActivityId(ActivityIdEnum.LOGIN.getId());
                    sysActivityBO.setUserId(userInfoPO.getId());
//                    sysActivityService.saveUserActivity(sysActivityBO);
                }
            }
        }catch (Exception e){
            log.error("sysActivityService.newUserLoginCoupon error", e);
        }
    }

    /*public void saveUserCoupon(String mobile){
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setMobile(mobile);
        userInfoPO = this.baseMapper.selectOne(userInfoPO);
        if(userInfoPO.getIs_send_coupon()==0) {
            try {
                sender.send(HuaYangConstant.MQ_SEND_COUPON,String.valueOf(userInfoPO.getId()),1000*1);
                userInfoPO.setIs_send_coupon(1);
                this.baseMapper.updateById(userInfoPO);
            } catch (Exception e) {
                log.error("sysActivityService.saveUserActivity error", e);
            }
        }
    }*/

    public void sendLotBean(String mobile){
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setMobile(mobile);
        userInfoPO = this.baseMapper.selectOne(userInfoPO);
        Wrapper firstRegisterWrapper = new EntityWrapper();
        firstRegisterWrapper.eq("user_id", userInfoPO.getId());
        firstRegisterWrapper.eq("type", "7");
        firstRegisterWrapper.eq("info", "用户注册奖励");
        Integer firstRegisterCount = userCashMapper.selectCount(firstRegisterWrapper);
        if (firstRegisterCount == 0) {
            saveUserCash(new BigDecimal(10),userInfoPO,7,"用户注册奖励",null);
        }
    }

    private void saveUserCash(BigDecimal money, UserInfoPO userInfoPO,Integer payWay,String info,Long orderId) {
        UserFundsPO fundsPO = userFundsMapper.selectById(userInfoPO.getId());
        boolean f = false;
        if(null == fundsPO){
            fundsPO = new UserFundsPO();
            fundsPO.setUser_id(userInfoPO.getId());
            fundsPO.setLot_bean(BigDecimal.ZERO);
            f = true;
        }
        fundsPO.setLot_bean(fundsPO.getLot_bean().add(money));

        UserCashPO userCashPO = new UserCashPO();
        userCashPO.setId(ymlConfig.getPkId());
        userCashPO.setUser_id(userInfoPO.getId());
        userCashPO.setReal_name(userInfoPO.getReal_name());
        userCashPO.setMobile(userInfoPO.getMobile());
        userCashPO.setPay_way(payWay);
        userCashPO.setPay_account("ZQXQ");
        userCashPO.setType(7);
        userCashPO.setStatus(4);
        userCashPO.setPay_amount(money);
        userCashPO.setInfo(info);
        userCashPO.setOrder_id(orderId);
        userCashService.insert(userCashPO);
        fundsPO.setBonus_status(1);

        if(f){
            userFundsMapper.insert(fundsPO);
        }
        else{
            fundsPO.setCreate_time(null);
            fundsPO.setUpdate_time(null);
            userFundsMapper.updateById(fundsPO);
        }
    }

    public void saveUserCoupon(String mobile){
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setMobile(mobile);
        userInfoPO = this.baseMapper.selectOne(userInfoPO);
        if(userInfoPO.getIs_send_coupon()==0) {
            try {
                SysActivityBO sysActivityBO = new SysActivityBO();
                sysActivityBO.setActivityId(ActivityIdEnum.REGISTER.getId());
                sysActivityBO.setUserId(userInfoPO.getId());
//                boolean b = sysActivityService.saveUserActivity(sysActivityBO);
                userInfoPO.setIs_send_coupon(1);
                this.baseMapper.updateById(userInfoPO);
            } catch (Exception e) {
                log.error("sysActivityService.saveUserActivity error", e);
            }
        }
        UserInviteRecordPO inviteRecordPO = new UserInviteRecordPO();
        inviteRecordPO.setUser_id(userInfoPO.getId());
        UserInviteRecordPO invitePO = userInviteMapper.selectOne(inviteRecordPO);
        if(invitePO!=null) {
            Wrapper firstRegisterWrapper = new EntityWrapper();
            firstRegisterWrapper.eq("user_id", invitePO.getInviter_id());
            firstRegisterWrapper.eq("type", "7");
            firstRegisterWrapper.eq("info", "用户首次邀请好友注册奖励");
            Integer firstRegisterCount = userCashMapper.selectCount(firstRegisterWrapper);
            if (firstRegisterCount == 0) {
                SysActivityBO sysActivityBO = new SysActivityBO();
                sysActivityBO.setActivityId(ActivityIdEnum.FIRST_INVITE_REGISTER_REWARD.getId());
                sysActivityBO.setUserId(userInfoPO.getId());
                sysActivityBO.setInviterId(String.valueOf(invitePO.getInviter_id()));
//                sysActivityService.saveUserActivity(sysActivityBO);
            }
            Wrapper inviterCountWrapper = new EntityWrapper();
            inviterCountWrapper.eq("user_id", invitePO.getInviter_id());
            inviterCountWrapper.like("create_time",f.format(new Date()));
            inviterCountWrapper.eq("type", "7");
            inviterCountWrapper.eq("info", "用户新增好友注册奖励");
            Integer inviterCashCount = userCashMapper.selectCount(inviterCountWrapper);
            SysConfigPO sysConfigPO = sysConfigMapper.getByKey("INVITATION_AWARDS");
            Integer inviteAwardCount = Integer.valueOf(sysConfigPO.getCval());
            if(inviterCashCount<inviteAwardCount){
                Wrapper wrapper1 = new EntityWrapper();
                wrapper1.eq("order_id", userInfoPO.getId());
                wrapper1.eq("type",7);
                wrapper1.eq("info","用户新增好友注册奖励");
                Integer count1 = userCashMapper.selectCount(wrapper1);
                if(count1==0) {
                    SysActivityBO sysActivityBO = new SysActivityBO();
                    sysActivityBO.setUserId(userInfoPO.getId());
                    sysActivityBO.setInviterId(String.valueOf(invitePO.getInviter_id()));
                    sysActivityBO.setActivityId(ActivityIdEnum.FIRST_TODAY_INVITE_REGISTER_REWARD.getId());
//                    sysActivityService.saveUserActivity(sysActivityBO);
                }
            }
        }
    }
    @Transactional
    @Override
    public void realAuth(UserInfoPO po) {
        this.baseMapper.updateById(po);
        UserFundsPO fundsPO = new UserFundsPO();
        fundsPO.setUser_id(po.getId());
        fundsPO.setReal_auth(1);
        if(userFundsMapper.updateById(fundsPO) < 1){
            userFundsMapper.insert(fundsPO);
        }
    }

    @Override
    public void updatePayPassword(Long userId, String payPassword) {
        this.baseMapper.updatePayPassord(userId, payPassword);
        UserFundsPO fundsPO = new UserFundsPO();
        fundsPO.setUser_id(userId);
        fundsPO.setPay_pwd(1);
        if(userFundsMapper.updateById(fundsPO) < 1){
            userFundsMapper.insert(fundsPO);
        }
    }

    @Override
    public void addUserAgent(UserInfoPO userInfoPO,String agentId) {
        Long userId = userInfoPO.getId();
        String mobile = userInfoPO.getMobile();
        String realName = userInfoPO.getReal_name();
        UserAgentPO userAgentPO = new UserAgentPO();
        userAgentPO.setUser_id(userId);
        userAgentPO.setAgent_id(agentId);
        userAgentPO.setName(realName);
        userAgentPO.setMobile(mobile);
        userAgentPO.setStatus(0);
        userAgentMapper.insert(userAgentPO);
    }
    @Override
    public void deleteUserAgent(Long userId,Integer status) {
        UserAgentPO userAgentPO = new UserAgentPO();
        userAgentPO.setUser_id(userId);
        userAgentPO.setStatus(status);
        userAgentMapper.updateById(userAgentPO);
    }
    @Override
    public void sendCoupons(String mobiles,Long couponId) {
        String key = "SEND_USER_COUPON";
        String value = stringRedisTemplate.opsForValue().get(key);
        try {
            if (StrUtils.isEmpty(value)) {
                stringRedisTemplate.opsForValue().set(key, key);
                Set<UserCouponPO> set = new HashSet();
                for (String mobile : mobiles.split(",")) {
                    UserInfoPO userInfoPO = new UserInfoPO();
                    userInfoPO.setMobile(mobile);
                    userInfoPO = baseMapper.selectOne(userInfoPO);
                    if(userInfoPO!=null){
                        addUserCoupon(userInfoPO.getId(), couponId, 0, 0, set);
                    }
                }
                List<UserCouponPO> list = new ArrayList(set);
                userCouponService.insertBatch(list);
            }
        } catch (Exception e) {
            log.error("发放失败：" + e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动开启事务回滚
        } finally {
            stringRedisTemplate.delete(key);
        }
    }
    @Override
    public void closureOrRelease(Long userId,Integer enabled) {
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setId(userId);
        userInfoPO = baseMapper.selectOne(userInfoPO);
        userInfoPO.setEnabled(enabled);
        baseMapper.updateById(userInfoPO);
        //如果禁用用户 同时禁用用户待开订单
        if (enabled == 1){
            userOrderMapper.disableOrderByUserId(userId);
        }
    }
    private void addUserCoupon(Long userId,Long couponId,Integer addDay,Integer status,Set<UserCouponPO> set) {
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("user_id",userId);
        wrapper.eq("coupon_id",couponId);
        Integer count = userCouponMapper.selectCount(wrapper);
        if(count==0){
            UserCouponPO userCouponPO = new UserCouponPO();
            userCouponPO.setCoupon_id(couponId);
            userCouponPO.setUser_id(userId);
            Date a = DateUtil.dateFormat(DateUtils.addDay(new Date(),addDay),"yyyy-MM-dd");
            userCouponPO.setStart_time(DateUtil.dateFormat(DateUtils.addDay(new Date(),addDay),"yyyy-MM-dd"));
            userCouponPO.setDistribute_time(DateUtil.dateFormat(DateUtils.addDay(new Date(),addDay),"yyyy-MM-dd"));
            userCouponPO.setEnd_time(DateUtil.dateFormat(DateUtils.addDay(new Date(),addDay+7),"yyyy-MM-dd"));
            userCouponPO.setStatus(status);
            set.add(userCouponPO);
        }
    }
    /**
    * @Author 苦智
    * @Description 根据代理人id统计代理人数据
    * @Date 17:43 2018/7/7
    * @Param [agentId, timeType, month]
    * @return java.util.Map<java.lang.String,java.lang.Object>
    **/
    @Override
    public Map<String, Object> queryAgentDataById(String agentId, Integer timeType, String month, Integer pageNo, Integer pageSize) {
        UserAgentPO userAgentPO = new UserAgentPO();
        userAgentPO.setAgent_id(agentId);
        UserAgentPO agentPO = userAgentMapper.selectOne(userAgentPO);
        if (agentPO == null)
            return null;
        long userId = agentPO.getUser_id();
        Page<Map<String,Object>> page = new Page(pageNo,pageSize);
        Map<String,Object> totalMap = userAgentMapper.queryTotalAgentDataById(userId,month);
        Map<String,Object> regDataMap = userAgentMapper.queryRegUserDataById(userId,month);
        totalMap.putAll(regDataMap);
        List<Map<String,Object>> pageMap = new ArrayList();
        if (timeType == 2){
            //按天查询
            pageMap = userAgentMapper.queryDayAgentDataById(page,userId,month);
        }else{
            //按月查询
            pageMap = userAgentMapper.queryMonthAgentDataById(page,userId,month);
        }
        page.setRecords(pageMap);
        totalMap.put("page",page);
        totalMap.put("name",agentPO.getName());
        return totalMap;
    }

    @Override
    public void updateUserInfo(Long userId, String headAddress,String nickName) {
        this.baseMapper.updateUserInfo(userId, headAddress,nickName);
    }

    @Override
    public Map<String, Object> taskCenter(Long userId) {
        Map<String,Object> map = new HashMap();
        Map<String,Object> sumProfitMap = this.baseMapper.getSumProfit(userId);
        map.put("sumProfit",sumProfitMap);
        List<Map<String,Object>> list1 = new ArrayList();
        List<Map<String,Object>> list2 = new ArrayList();
        List<Map<String,Object>> list3 = new ArrayList();
        Map<String,Object> taskMap = new HashMap();
        Map<String,Object> map1 = this.baseMapper.getTask1(userId);
        Map<String,Object> map2 = this.baseMapper.getTask2(userId);
        Map<String,Object> map3 = this.baseMapper.getTask3(userId);
        Map<String,Object> map4 = this.baseMapper.getTask4(userId);
        Map<String,Object> map5 = this.baseMapper.getTask5(userId);
        Map<String,Object> map6 = this.baseMapper.getTask6(userId);
        Map<String,Object> map7 = this.baseMapper.getTask7(userId);
        Map<String,Object> map8 = this.baseMapper.getTask8(userId);
        Map<String,Object> map9 = this.baseMapper.getTask9(userId);
        Map<String,Object> map10 = this.baseMapper.getTask10(userId);
        Map<String,Object> map11 = this.baseMapper.getTask11(userId);
        Map<String,Object> map12 = this.baseMapper.getTask12(userId);
        Map<String,Object> map13 = this.baseMapper.getTask13(userId);
        Map<String,Object> map14 = this.baseMapper.getTask14(userId);
        Map<String,Object> map15 = this.baseMapper.getTask15(userId);
        Map<String,Object> map16 = this.baseMapper.getTask16(userId);
        Map<String,Object> map17 = this.baseMapper.getTask17(userId);
        Map<String,Object> map18 = this.baseMapper.getTask18(userId);
        Map<String,Object> map19 = this.baseMapper.getTask19(userId);
        Map<String,Object> map20 = this.baseMapper.getTask20(userId);
        list1.add(map1);list1.add(map2);list1.add(map3);list1.add(map4);
        list2.add(map5);list2.add(map6);list2.add(map7);list2.add(map8);list2.add(map9);list2.add(map10);list2.add(map11);list2.add(map12);list2.add(map13);list2.add(map14);list2.add(map15);
        list3.add(map16);list3.add(map17);list3.add(map18);list3.add(map19);list3.add(map20);
        taskMap.put("1",list1);
        taskMap.put("2",list2);
        taskMap.put("3",list3);
        map.put("taskMap",taskMap);
        return map;
    }

    @Override
    public Map<String, Object> inviteUsersData(Long userId) {
        Map<String,Object> map = this.baseMapper.inviteUsersData(userId);
        return map;
    }

}
